const mongoose=require("mongoose");
mongoose.connect("mongodb://localhost/test");
mongoose.Promise=Promise;

const Schema=mongoose.Schema({
        name:String,
        age:Number
      });

    var User=new mongoose.model("User",Schema);

    async function run(){
      await User.create([
            {name:"mingzhen",age:16},
            {name:"mingzhen",age:17},
            {name:"mingzhen",age:18},
            {name:"maosen",age:18},
            {name:"maosen",age:19},
            {name:"maosen",age:20}
      ]);
      run();
          // console.log(await User.find({name:"age"}));
          //这里不用加await
          const query=User.find();
          //这里不用创建变量
          query.where(name).eq("mingzhen");
              cosnt result=await query;
              //这里返回的也是一个数组，包含着对应的数组对象同 await User.find({name:"mingzhen"})结果相同
              console.log(result);
        //这种写法也可以，不过没有那么直观
        //  console.log(await User.find().where(name).eq("mingzhen"));


          var query1=User.find();
          //使用query查询的另一优点是它能使用不等于作为查询条件，更加灵活，并且支持任何字段。
              query.where(name).ne("mingzhen");
              console.log(await query);
